home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr11 / ddj9304.zip / OS2WPS.ZIP / WPSPREAD.C < prev    next >
C/C++ Source or Header  |  1993-01-18  |  6KB  |  144 lines

  1. [LISTING FOUR]
  2.  
  3. /* This file was generated by the SOM Compiler. FileName: wpspread.c.
  4.  * Generated using: SOM Precompiler spc: 1.22 SOM Emitter emitc: 1.24 */
  5. #define WPSpread_Class_Source
  6. #include "wpspread.ih"
  7.  
  8. BOOL openfile ( PSZ szFname, LONG alValues[] );
  9. BOOL printspread ( WPSpread *somSelf, PPRINTDEST pPrintDest );;
  10.  
  11. #undef SOM_CurrentClass
  12. #define SOM_CurrentClass SOMMeta
  13. SOM_Scope PSZ   SOMLINK wpspreadM_wpclsQueryTitle(M_WPSpread *somSelf)
  14. {
  15.     M_WPSpreadData *somThis = M_WPSpreadGetData(somSelf);
  16.     M_WPSpreadMethodDebug("M_WPSpread","wpspreadM_wpclsQueryTitle");
  17.     return _wpclsQueryInstanceType( somSelf );
  18. }
  19. SOM_Scope void   SOMLINK wpspreadM_wpclsInitData(M_WPSpread *somSelf)
  20. {
  21.     HMODULE hmod;               // module handle
  22.     PSZ     psz;                // module file name
  23.     APIRET  rc;                 // return from API
  24.     M_WPSpreadData *somThis = M_WPSpreadGetData(somSelf);
  25.     M_WPSpreadMethodDebug("M_WPSpread","wpspreadM_wpclsInitData");
  26.   // initialize the parent classes first
  27.     parent_wpclsInitData ( somSelf );
  28.   // query our module name
  29.     psz = _somLocateClassFile( SOMClassMgrObject, SOM_IdFromString( "WPChart" )
  30.                           , WPSpread_MajorVersion , WPSpread_MinorVersion );
  31.   // query our module handle
  32.     if ( psz != NULL )
  33.         rc = DosQueryModuleHandle ( psz, &hmod );
  34.   // load the icon (same as pointer) and store in class data
  35.     _hicon = WinLoadPointer ( HWND_DESKTOP, hmod, 1 );
  36. }
  37. SOM_Scope HPOINTER   SOMLINK wpspreadM_wpclsQueryIcon(M_WPSpread *somSelf)
  38. {
  39.     M_WPSpreadData *somThis = M_WPSpreadGetData(somSelf);
  40.     M_WPSpreadMethodDebug("M_WPSpread","wpspreadM_wpclsQueryIcon");
  41.     return _hicon;
  42. }
  43. SOM_Scope PSZ   SOMLINK wpspreadM_wpclsQueryInstanceFilter(M_WPSpread *somSelf)
  44. {
  45.     M_WPSpreadData *somThis = M_WPSpreadGetData(somSelf);
  46.     M_WPSpreadMethodDebug("M_WPSpread","wpspreadM_wpclsQueryInstanceFilter");
  47.     return ".SPR";
  48. }
  49. SOM_Scope PSZ   SOMLINK wpspreadM_wpclsQueryInstanceType(M_WPSpread *somSelf)
  50. {
  51.     M_WPSpreadData *somThis = M_WPSpreadGetData(somSelf);
  52.     M_WPSpreadMethodDebug("M_WPSpread","wpspreadM_wpclsQueryInstanceType");
  53.     return "XX Company Spreadsheet";
  54. }
  55. #undef SOM_CurrentClass
  56. #define SOM_CurrentClass SOMInstance
  57. SOM_Scope BOOL   SOMLINK wpspread_wpPrintObject(WPSpread *somSelf,
  58.         PPRINTDEST pPrintDest,
  59.         ULONG ulReserved)
  60. {
  61.     /* WPSpreadData *somThis = WPSpreadGetData(somSelf); */
  62.     WPSpreadMethodDebug("WPSpread","wpspread_wpPrintObject");
  63.     return printspread ( somSelf, pPrintDest );
  64. }
  65. //************* Following code NOT generated by SOM compiler
  66. // printspread: prints the file this object represents
  67. //      RETURNS:  TRUE if successful, FALSE if not
  68. BOOL printspread ( WPSpread *somSelf, PPRINTDEST pPrintDest )
  69. {
  70.     HDC     hdcPrinter;             // printer DC
  71.     HAB     hab;                    // anchor block handle
  72.     HPS     hps;                    // micro PS
  73.     SIZEL   sizel;                  // presentation page size
  74.     LONG    alValues[2];            // spreadsheet values
  75.     BOOL    fSuccess;               // return from API
  76.     BOOL    lSuccess;               // return from API
  77.     CHAR    szFname[255];           // file name
  78.     ULONG   cb;                     // filename length
  79.     POINTL  ptl;                    // drawing coordinates
  80.     CHAR    sz[50];                 // temporary string
  81.   // create a printer device context
  82.     hab = WinQueryAnchorBlock ( HWND_DESKTOP );
  83.     hdcPrinter = DevOpenDC ( hab , pPrintDest->lType
  84.                 , pPrintDest->pszToken , pPrintDest->lCount
  85.                 , pPrintDest->pdopData , NULLHANDLE );
  86.   // create a micro PS associated with the printer DC
  87.     sizel.cx = sizel.cy = 0;
  88.     hps = GpiCreatePS ( hab, hdcPrinter, &sizel
  89.             , GPIT_MICRO | PU_LOENGLISH | GPIA_ASSOC );
  90.   // open the file associated with this object
  91.     cb = 255;
  92.     _wpQueryRealName ( somSelf, szFname, &cb, TRUE );
  93.     fSuccess = openfile ( szFname , alValues );
  94.   // start a printer job
  95.     lSuccess = DevEscape ( hdcPrinter, DEVESC_STARTDOC
  96.             , strlen ( _wpQueryTitle ( somSelf ) )
  97.             , _wpQueryTitle ( somSelf ) , NULL, NULL );
  98.   // print the values
  99.     ptl.x = 100; ptl.y = 125;
  100.     _itoa ( alValues[0], sz, 10 );
  101.     lSuccess = GpiCharStringAt ( hps, &ptl, strlen ( sz ) , sz );
  102.     ptl.y = 100;
  103.     _itoa ( alValues[1], sz, 10 );
  104.     lSuccess = GpiCharStringAt ( hps, &ptl, strlen ( sz ) , sz );
  105.     ptl.y = 75;
  106.     lSuccess = GpiMove ( hps, &ptl );
  107.     ptl.x = 200;
  108.     lSuccess = GpiLine ( hps, &ptl );
  109.     ptl.x = 100; ptl.y = 50;
  110.     _itoa ( alValues[0] + alValues[1], sz, 10 );
  111.     lSuccess = GpiCharStringAt ( hps, &ptl, strlen ( sz ) , sz );
  112.   // end a printer job
  113.     lSuccess = DevEscape ( hdcPrinter, DEVESC_ENDDOC , 0 , NULL, NULL, NULL );
  114.   // clean up
  115.     DevCloseDC ( hdcPrinter );
  116.     GpiDestroyPS ( hps );
  117.     return TRUE;
  118. }
  119. // openfile: reads spreadsheet values from the specified file
  120. //      RETURNS:  TRUE if successful, FALSE if not
  121. BOOL openfile ( PSZ szFname, LONG alValues[] )
  122. {
  123.     HFILE   h;                  // file handle
  124.     ULONG   ulAction;           // action taken by OPEN
  125.     ULONG   ulActualRead;       // count read from file
  126.     APIRET  rc;                 // return code
  127.   // open the file
  128.     rc = DosOpen ( szFname, &h, &ulAction, 0L
  129.             , 0, OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW
  130.             , OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE, NULL );
  131.     if ( rc != 0 )
  132.         return FALSE;
  133.   // read the values
  134.     rc = DosRead ( h, alValues, 8, &ulActualRead );
  135.     if ( ( rc != 0 )  || ( ulActualRead != 8 ) )
  136.     {
  137.         DosClose ( h );
  138.         return FALSE;
  139.     }
  140.   // close the file
  141.     DosClose ( h );
  142.     return TRUE;
  143. }
  144.